package org.peoplesearch.commons;


import com.google.common.collect.AbstractIterator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.AbstractCollection;
import java.util.Iterator;

public class IdIterator extends AbstractCollection<Long> {

    private String fileName;

    public IdIterator(String fileName) {
        this.fileName = fileName;
    }

    public Iterator<Long> iterator() {
        final BufferedReader reader;
        try {
            reader = new BufferedReader(new FileReader(new File(fileName)));
            Integer.parseInt(reader.readLine());

            return new AbstractIterator<Long>() {
                @Override
                protected Long computeNext() {
                    try {
                        String line = reader.readLine();
                        if (line == null) {
                            reader.close();
                            return endOfData();
                        }
                        return Long.parseLong(line);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            };
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    public int size() {
        return 0;
    }

}
